package robocup.component.speechacts.coachlanguage;

import robocup.component.geometry.Vektor;

public class CPoint {

  private TypeConstants.POINTTYPE pointType  = TypeConstants.POINTTYPE.INIT;

  private double                  x          = 0;

  private double                  y          = 0;

  private boolean                 teamOur    = false;

  private int                     unumInt    = 0;

  private String                  unumString = "";

  private CPoint                  point      = null;

  private PointArith              pointArith = null;

  public PointArith getPointArith() {

    return this.pointArith;
  }

  public void setPointArith(final PointArith pointArith) {

    this.pointArith = pointArith;
    this.pointType = TypeConstants.POINTTYPE.POINT_ARITH;
  }

  public int getUnumInt() {

    return this.unumInt;
  }

  public void setUnumInt(final int unumInt) {

    this.unumInt = unumInt;
    this.pointType = TypeConstants.POINTTYPE.UNUM;
  }

  public String getUnumString() {

    return this.unumString;
  }

  public void setUnumString(final String unumString) {

    this.unumString = unumString;
    this.pointType = TypeConstants.POINTTYPE.UNUM;
  }

  public boolean isTeamOur() {

    return this.teamOur;
  }

  public void setTeamOur(final boolean teamOur) {

    this.teamOur = teamOur;
    this.pointType = TypeConstants.POINTTYPE.UNUM;
  }

  public boolean isBall() {

    return (this.pointType == TypeConstants.POINTTYPE.BALL);
  }

  public void setBall() {

    this.pointType = TypeConstants.POINTTYPE.BALL;
  }

  public Vektor getVektor() {

    final Vektor v = new Vektor();
    v.setX(this.x);
    v.setY(this.y);
    return v;
  }

  public double getX() {

    return this.x;
  }

  public void setX(final double x) {

    this.x = x;
    this.pointType = TypeConstants.POINTTYPE.XY;
  }

  public double getY() {

    return this.y;
  }

  public void setY(final double y) {

    this.y = y;
    this.pointType = TypeConstants.POINTTYPE.XY;
  }

  public TypeConstants.POINTTYPE getPointType() {

    return this.pointType;
  }

  public void setPointType(final TypeConstants.POINTTYPE pointType) {

    this.pointType = pointType;
  }

  public CPoint getPoint() {

    return this.point;
  }

  public void setPoint(final CPoint point) {

    this.point = point;
    this.pointType = TypeConstants.POINTTYPE.XY_POINT;
  }

  @Override
  public String toString() {

    final StringBuffer buf = new StringBuffer();

    switch (this.pointType) {

      case INIT:
        buf.append("(empty point)");
        break;

      case BALL:
        buf.append("(pt ball)");
        break;

      case XY:
        buf.append("(pt " + this.x + " " + this.y + ")");
        break;

      case XY_POINT:
        buf
            .append("(pt " + this.x + " " + this.y + " " + this.point
                .toString() + ")");
        break;

      case UNUM:
        String str = "";
        if (this.teamOur) {
          str = "our";
        }
        else {
          str = "opp";
        }
        String unum = "";
        if (this.unumString.matches("")) {
          unum = " " + this.unumInt;
        }
        else {
          unum = " " + this.unumString;
        }

        buf.append("(pt " + str + unum + ")");
        break;

      case POINT_ARITH:
        buf.append("(" + this.pointArith.toString() + ")");
        break;
    }

    return buf.toString();
  }

}
